using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	[AddComponentMenu("MaterialUI/FPSCounter", 100)]
	public class FPSCounter : MonoBehaviour
	{
		[SerializeField]
		private float m_UpdateInterval = 0.5f;

		[SerializeField]
		private Text m_Text;

		private float m_DeltaFps;

		private int m_Frames;

		private float m_Timeleft;

		public float updateInterval
		{
			get
			{
				return m_UpdateInterval;
			}
			set
			{
				m_UpdateInterval = value;
			}
		}

		public Text text
		{
			get
			{
				if (m_Text == null)
				{
					m_Text = base.gameObject.GetAddComponent<Text>();
				}
				return m_Text;
			}
			set
			{
				m_Text = value;
			}
		}

		private void Start()
		{
			m_Timeleft = updateInterval;
		}

		private void Update()
		{
			m_Timeleft -= Time.deltaTime;
			m_DeltaFps += Time.timeScale / Time.deltaTime;
			m_Frames++;
			if (m_Timeleft <= 0f)
			{
				text.text = string.Empty + (m_DeltaFps / (float)m_Frames).ToString("f2") + " FPS";
				if (m_DeltaFps / (float)m_Frames < 1f)
				{
					text.text = string.Empty;
				}
				m_Timeleft = updateInterval;
				m_DeltaFps = 0f;
				m_Frames = 0;
			}
		}
	}
}
